<?php
/**
 * Created by PhpStorm.
 * User: Dell
 * Date: 2019-1-2
 * Time: 15:10
 */

namespace app\index\controller;


use think\Controller;

class Alipay extends Controller
{
    public function alipay(){
        include_once substr(getcwd(),0,-7).'/extend/alipay/pc.php';
        header('Content-type:text/html; Charset=utf-8');
        $appid = '2018042560039194';			//https://open.alipay.com 账户中心->密钥管理->开放平台密钥，填写添加了电脑网站支付的应用的APPID
        $returnUrl = 'http://www.xxx.com/alipay/return.php';     //付款成功后的同步回调地址
        $notifyUrl = 'http://www.xxx.com/alipay/notify.php';     //付款成功后的异步回调地址
        $outTradeNo = uniqid();     //你自己的商品订单号，不能重复
        $payAmount = 0.01;          //付款金额，单位:元
        $orderName = '支付测试';    //订单标题
        $signType = 'RSA2';			//签名算法类型，支持RSA2和RSA，推荐使用RSA2
        $rsaPrivateKey='MIIEpAIBAAKCAQEAn5SEEERN7FvJTW81vh5aYwNDWixkSFWrY+DcnYJU4aQWjb7OiamdKGlLie5WsHLQd3gzBBYH8mccagxyMtWduw3FNhrjH7NykLooD8jz33Em8C5zX6symJ629zJV54MRQkHcisD3FZlE1h/+0dSRSC7QMJSwfZGt58+ynaWGkl6RSZ9yod6KMdxBTavyRY8uQI87ZPNTWs0lagSUVsQjWG5bz8g64rLl9b+w25M8IMSWPqBEi9GEJH6kU7LZWp4A5DFtugu0ZWk7GYhZu6LLetJ/YOYkGSorlukEmCCwRnHWYDUv1UPFdELTJM3REp+MUY4PKq+cuMvtxYSbyZd6awIDAQABAoIBAFWxki2OEG5BZ9suQiTi9dS/ttZgikWRw6Sx5qaqi1xUGkxpz017iMpfqNHb7C96qFnPcU3bas8P8eE858JGlhoRrfp8+8RVP8taPBMl7Vfq0mcd+pTAQT5V1JjwLdNRvd3fskfMkaLGmIGH0vXo+U9S3DeKUTBNH58hGKCxd493Yed/5N+uuFTGlAtE/AxXSMlOwSVTtm35wm/LEkPqsTrkMYmX9fS6bTJ6QUx4mtJ2c/wZhtubapeRDhtXGmVtjc1dg4G5U763ImxKtH0hbCWlUFDZjn9CJIhyUnEqjaN9jTDCgzlpJFPFhTMSzeODaZoJbLGrZLWuL1FfLXvn75ECgYEAyrMKeNKbD4hdS/nL9vp8Mozo0hgU71gdgg+jt7yXuHDQxL6PvjlC8O8rymRrE5HwkL8ZaqS+J0Wk7ko+wF0qNL3BMYm95LiRH8IFvCk97I81VIZ0cyva1RF9qBBAWHaC27apRsp1PJo8WT2MvhIguWGGwH2MKjLPtPzx8yPEw8kCgYEAyYrZpCyBxI6Lt/EmTlcS+Zo8x53aZh9NIrDSKfD72qkxXKDLb5ITwezhzuvDOEjBDBPHKZcZ86R2lL17Ao9WFK54bx0LC6LI7LJdHIlWnIORbVpEThY8rmVr3TqrFTs9oT0VXtkXqA75oVUShu2aKNPp5ll0qwOajS6CchkdnpMCgYEAm8xz/xw5rP2uYEhXGrW7IoumJF34MWN0AtUMjJw7rbug66hhCeAvcMsUyJLYrokc89S+r3aC5eKk+7c7dlXlq/Yx+Waa+6NVgKh8Cf1VKG+GmTpjZWbO47h28efT3Wrx9/j1MYFKDVOrkRg7BpkeZ/7rOScGxiSZ+830FmNmyOkCgYB1l1wRHB7C7mC6/CrbfpaFp+ZamdF50D2TRhP5gK+SDzHL182a1WJNvcaqkoie6GQqhceojo8Hxyeg9UU2YydYfcurGQj+ywXshM0q/z7XpzRM12QPI45YOrjKpZZ4ls4Iq7kyU/wnhEVGSnq62xsdQzevvPYDaeDdCwv1Qo4znQKBgQCd+wTviOuiJMToQJDgoT5BRoUqbSkO9t//gNQmceHNz0HG65bw4JyIHXZXAoicGUdrqf+/Drgx8bD0Kj0TkuTMaRlMPbO0EepLxUgGeWLZfDDg79dvIIiYlN7eD1u9CC/ptGbKurdipYkFRlXNJDw87WCuNSkOwsw/F/WJyN8nHA==';		//商户私钥，填写对应签名算法类型的私钥，如何生成密钥参考：https://docs.open.alipay.com/291/105971和https://docs.open.alipay.com/200/105310
        /*** 配置结束 ***/
        $aliPay = new \AlipayService();
        $aliPay->setAppid($appid);
        $aliPay->setReturnUrl($returnUrl);
        $aliPay->setNotifyUrl($notifyUrl);
        $aliPay->setRsaPrivateKey($rsaPrivateKey);
        $aliPay->setTotalFee($payAmount);
        $aliPay->setOutTradeNo($outTradeNo);
        $aliPay->setOrderName($orderName);
        $sHtml = $aliPay->doPay();
        echo $sHtml;
    }
}